package net.zozoo.spring6;

import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.lang.reflect.Constructor;

public class TestUser {

    @Test
    public void testUserObject() {
        ApplicationContext content =
                new ClassPathXmlApplicationContext("bean.xml");

        System.out.println("进入单元测试");

        //获取创建对象
        User user = (User) content.getBean("user");

        //调用对象方法
        user.add();
    }

    @Test
    public void testUserReflection() throws Exception {
        Class c = Class.forName("net.zozoo.spring6.User");
        Constructor struct = c.getDeclaredConstructor();
        struct.setAccessible(true);
        User user = (User) struct.newInstance();
        user.add();
    }
}
